package org.ala.clickhouse.xml;

import org.ala.clickhouse.xml.fields.CKField;
import org.ala.tiktools.tools.Assert;

/**
 *  分组
 *
 *	@author ala
 *	@date 2025年6月9日
 */
public class GroupBy {

	/**
	 * 	参与分组的字段
	 */
	@SuppressWarnings("rawtypes")
	protected CKField[] fields;
	/**
	 * 	生成的sql
	 */
	protected String sql;
	public String getSql() {
		return sql;
	}
	
	
	@SuppressWarnings("rawtypes")
	public static GroupBy fields(CKField... fields) {
		Assert.assertTrue(fields.length > 0, "分组字段不能为空");
		GroupBy gb = new GroupBy();
		gb.fields = fields;
		
		StringBuilder sbuf = new StringBuilder("GROUP BY ");
		for (CKField f : fields) {sbuf.append(f.getColumn()).append(",");}
		gb.sql = sbuf.substring(0, sbuf.length()-1);
		return gb;
	}
}
